<?php 

function twentyeleven_comment( $comment, $args, $depth ) {
	$GLOBALS['comment'] = $comment;
	switch ( $comment->comment_type ) :
	case 'pingback' :
	case 'trackback' :
		?>
<li class="post pingback">
	<p><?php _e( 'Pingback:', 'twentyeleven' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?></p>
		<?php
				break;
			default :
		?>
		
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
	<article id="comment-<?php comment_ID(); ?>" class="comment">
		<footer class="comment-meta">
			<div class="comment_uper">
				<strong class="re_lou"><?php printf(__('%1$s floor', 'News-feed'), 2);?></strong>
				<span class="re_username"><?php echo get_comment_author_link();?></span>
				<span class="re_area"><?php printf(__('Comes from [%1$s]', 'News-feed'), '武汉');?></span>
				<span class="datetime"><?php printf(__('Public at %1$s %2$s', 'News-feed'), get_comment_date(), get_comment_time());?></span>
			</div>
	
					<?php if ( $comment->comment_approved == '0' ) : ?>
						<em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentyeleven' ); ?></em>
			<br />
					<?php endif; ?>
	
				</footer>
		<div class="avatar">
				<?php 
				$avatar_size = 68;
				if ( '0' != $comment->comment_parent ){
					$avatar_size = 39;
				} 
				echo get_avatar($comment, $avatar_size);
				?>
				</div>
		<div class="word-plan">
			<div class="comment-content"><?php comment_text(); ?></div>

			<div class="reply">
				<span>
					<?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply <span>&darr;</span>', 'twentyeleven' ), 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
				</span>
			</div>
			<!-- .reply -->
		</div>
	</article>
	<!-- #comment-## -->
	
		<?php
				break;
		endswitch;
}

function twentyeleven_posted_on(){
	$output = sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span><a href="%4$s" title="%5$s" rel="bookmark"><time class="entry-date" datetime="%6$s" pubdate>%7$s</time></a>',
	esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
	esc_attr( sprintf( __( 'View all posts by %s', 'twentyeleven' ), get_the_author() ) ),
	get_the_author(),
	esc_url( get_permalink() ),
	esc_attr( get_the_time() ),
	esc_attr( get_the_date( 'c' ) ),
	esc_html( get_the_date() ));

	echo $output;
}

function twentyeleven_posted_on_profile(){
	$output = sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s" pubdate>%4$s</time></a>',
			esc_url( get_permalink() ),
			esc_attr( get_the_time() ),
			esc_attr( get_the_date( 'c' ) ),
			esc_html( get_the_date() ),
			get_comments_number());
	
	$output .=  sprintf(__('<span class="profile-comment-num">%d comments</span>', 'News-feed'), get_comments_number());

	echo $output;
}

function News_feed_post_image_source($post_id, $big){
	if ($big){
		return get_post_meta($post_id, '_post_image_big', true);
	} else {
		return get_post_meta($post_id, '_post_image_small', true);
	}
}

function twentyeleven_content(){
	echo get_the_excerpt();
}

add_action('after_setup_theme', 'news_feed_setup');
function news_feed_setup(){
	load_child_theme_textdomain('News-feed', get_stylesheet_directory().'/languages');
	
	require (get_stylesheet_directory().'/widgets.php');
	remove_filter('body_class', 'twentyeleven_body_classes');
	
	require (ABSPATH . 'wp-admin/includes/plugin.php');
	if (is_plugin_active('theme-my-login/theme-my-login.php')) {
		require (get_stylesheet_directory().'/function-theme-my-login.php');
	}
	
	if (is_plugin_active('wp-user-frontend/wpuf.php')) {
		require (get_stylesheet_directory().'/function-wp-user-frontend.php');
	}
}

add_action('widgets_init', 'news_feed_widgets_init');

function news_feed_widgets_init(){
	register_widget('News_feed_Widget_recent_news');
}

function News_feed_body_classes( $classes ) {

	if ( function_exists( 'is_multi_author' ) && ! is_multi_author() )
		$classes[] = 'single-author';

	/*if ( is_singular() && ! is_home() && ! is_page_template( 'showcase.php' ) && ! is_page_template( 'sidebar-page.php' ) )
		$classes[] = 'singular';*/

	return $classes;
}

function News_feed_get_logo_url(){
	return bloginfo('stylesheet_directory').'/images/logo.png';
}

add_filter( 'body_class', 'News_feed_body_classes' );

function add_comment_form_before(){
	$user = wp_get_current_user();
	$avatar_size = 68;
	
	echo '<div class="comment_form_before">';
	if (is_user_logged_in()){
		echo '<div class="comment_form_avatar">';
		echo get_avatar($user->$ID, $avatar_size);
		echo '</div>';
	}
}

add_filter ('comment_form_before', 'add_comment_form_before');

function add_comment_form_after(){
	echo '</div>';
}

add_filter ('comment_form_after', 'add_comment_form_after');

function news_feed_comment_form_logged_in(){
	return null;
}

add_filter ('comment_form_logged_in', 'news_feed_comment_form_logged_in');

function build_page_steps(){
	global $wp_query, $paged;
	if ($paged < 1){
		$paged = 1;
		}
	?>
	<div class="page_steps">
	<?php 
	if ($paged >= 5){
	?>
	<span class="first"><a href="<?php echo get_pagenum_link(1);?>">|&lt;</a></span>
	<?php 
	}
	if ($paged >= 2) {
	?>
	<span class="prev"><a href="<?php previous_posts(true);?>">&lt;</a></span>
	<?php 
	}
	$begin_page = $paged > 3 ? $paged - 3 : 1;
	$end_page = $wp_query->max_num_pages - $paged <= 3 ? $wp_query->max_num_pages : $paged + 3;
	
	for ($i = $begin_page; $i <= $end_page; $i++){
		if ($i != $paged){
		?>
		<a href="<?php echo get_pagenum_link($i);?>"><?php echo $i;?></a>
		<?php 
		}
		else{
		?>
		<b><?php echo $i;?></b>
		<?php
		}
	}
	if ($wp_query->max_num_pages > $paged){
	?>
	<span class="next"><a
			href="<?php next_posts($wp_query->max_num_pages, true);?>">&gt;</a></span>
	<?php 
	}
	if ($wp_query->max_num_pages - $paged >= 4){
	?>
		<span class="end"><a
			href="<?php echo get_pagenum_link($wp_query->max_num_pages);?>">|&gt;</a></span>
	<?php 
	}
	?>
	</div><?php 
}


add_filter( 'pre_option_link_manager_enabled', '__return_true' );
add_action( 'save_post', 'using_id_as_slug', 10, 2 );
function using_id_as_slug($post_id, $post){
	global $post_type;	if($post_type=='post'){ //只对文章生效		// 如果是文章的版本，不生效
		if (wp_is_post_revision($post_id))
			return false;
		// 取消挂载该函数，防止无限循环
		remove_action('save_post', 'using_id_as_slug' );
		// 使用文章ID作为文章的别名
		wp_update_post(array('ID' => $post_id, 'post_name' => $post_id ));
		// 重新挂载该函数
		add_action('save_post', 'using_id_as_slug' );
	}
}
?>